package nl.windgazer.arachne.internal;

import javax.servlet.http.HttpServletRequest;

public class URLHelper {

	public static String getFullURL(final String partialUrl, final HttpServletRequest request) {
		if (!partialUrl.startsWith("http:")&&!partialUrl.startsWith("https:")) {
			final StringBuilder sb = new StringBuilder();
			sb.append(request.isSecure()?"https://":"http://");
			sb.append(request.getServerName());
			if (request.getServerPort()!=80&&request.getServerPort()!=443) {
				sb.append(':');
				sb.append(request.getServerPort());
			}
			sb.append(partialUrl);
			return sb.toString();
		}
		return partialUrl;
	}

}
